package xyz.xtt.pay.enums;

import java.util.Arrays;
import java.util.Objects;

import com.google.common.primitives.Ints;

/**
 * @author huqibo
 * 
 *         支付状态
 */
public enum DealStateEnum {
	/**
	 * 未支付
	 */
	NOT_PAYED(0, "未支付"), 
	/**
	 * 已支付
	 */
	PAID(1, "已支付"), 
	/**
	 * 已取消
	 */
	CANCEL(2, "已取消"), 
	/**
	 * 已取消
	 */
	EXPIRE(3, "已取消"), 
	/**
	 * 已完成
	 */
	COMPLETE(4, "已完成"),
	/**
	 * 待退款
	 */
	NEED_REFUND(5, "待退款"),
	/**
	 * 退款中
	 */
	REFUNDING(6, "退款中"),
	/**
	 * 已退款
	 */
	REFUNDED(7, "已退款");

	/**
	 * 编码
	 */
	private int code;
	/**
	 * 描述
	 */
	private String desc;

	DealStateEnum(int code, String desc) {
		this.code = code;
		this.desc = desc;
	}

	public int code() {
		return code;
	}

	public String desc() {
		return desc;
	}

	public static boolean checkType(String checkType) {
		return Arrays.asList(DealStateEnum.values()).stream().anyMatch(x -> Objects.equals(x.name(), checkType));
	}

	public static DealStateEnum convert(String checkType) {
		return Arrays.asList(DealStateEnum.values()).stream().filter(x -> Objects.equals(x.name(), checkType))
				.findFirst().orElse(null);
	}

	public static DealStateEnum queryConvert(String checkType) {
		return Arrays.asList(DealStateEnum.values()).stream()
				.filter(x -> Objects.equals(x.code(), Ints.tryParse(checkType))).findFirst().orElse(null);
	}

	public static DealStateEnum getByCode(int code) {
		return Arrays.asList(DealStateEnum.values()).stream().filter(x -> Objects.equals(x.code(), code))
				.findFirst().orElse(null);
	}

}
